package com.zzb.framework.starter.xxljob.service;

import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.service.XxlJobService;
import com.xxl.job.core.biz.model.ReturnT;
import com.zzb.framework.common.BasePage;
import com.zzb.framework.common.BaseResponse;
import com.zzb.framework.starter.xxljob.form.XxlJobInfoSearchForm;
import com.zzb.framework.starter.xxljob.utils.ReturnTConverter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MyXxlJobService {
    @Autowired
    private XxlJobInfoService xxlJobInfoService;

    @Autowired
    private XxlJobService xxlJobService;

    public BasePage<com.zzb.framework.starter.xxljob.model.XxlJobInfo> pageList(XxlJobInfoSearchForm searchForm) {
        if (StringUtils.isBlank(searchForm.getOrderBy())) {
            searchForm.setOrderBy("t.id DESC");
        }
        return xxlJobInfoService.queryPage(searchForm);
    }

    public BaseResponse<String> add(XxlJobInfo jobInfo) {
        ReturnT<String> ret = xxlJobService.add(jobInfo);
        return ReturnTConverter.convert(ret);
    }

    public BaseResponse<String> update(XxlJobInfo jobInfo) {
        ReturnT<String> ret = xxlJobService.update(jobInfo);
        return ReturnTConverter.convert(ret);
    }

    public BaseResponse<String> remove(int id) {
        ReturnT<String> ret = xxlJobService.remove(id);
        return ReturnTConverter.convert(ret);
    }

    public BaseResponse<String> stop(int id) {
        ReturnT<String> ret = xxlJobService.stop(id);
        return ReturnTConverter.convert(ret);
    }

    public BaseResponse<String> start(int id) {
        ReturnT<String> ret = xxlJobService.start(id);
        return ReturnTConverter.convert(ret);
    }
}
